package com.times.server.event;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;

/**
 * Spring事件驱动模型-消费者
 * @author TimesPanda
 */
@Component   //假如spring的IOC容器
@EnableAsync //允许异步执行
public class Consumer implements ApplicationListener<LoginEvent> {
    //日志
    private static final Logger log = LoggerFactory.getLogger(Consumer.class);

    /**
     * 监听消费消息
     * @param event
     */
    @Override
    @Async
    public void onApplicationEvent(LoginEvent event) {
        //打印日志信息
        log.info("Spring事件驱动模型-接受消息：{}",event);
    }
}
